package com.chenguo.testRabbit.controller;

import com.chenguo.testRabbit.config.RabbitQueueAndExchangeConfig;
import com.chenguo.testRabbit.pojo.User;
import com.chenguo.testRabbit.service.TestService;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class TestController {

    @Autowired
    private RabbitTemplate template;



    @Autowired
    TestService testService;

    @GetMapping("/hello/{num}")
    public User hello(@PathVariable(name = "num",required = true) int num){

        User user = testService.selectById(num);


        return user;

    }
    @GetMapping("/sendMQ")
    public String send() {
        template.convertAndSend("directExchange","direct","直连模式");


        template.convertAndSend("topicExchange","topic.#","订阅模式");

        template.convertAndSend("fanoutExchange","广播模式");

        template.convertAndSend("deadLetterExchange","deadLetterKey","死信队列模式");

        return "ok";

    }


    @GetMapping("/hello2")
    public User hello1(@RequestParam("num") int num){

        User user = testService.selectById(num);


        return user;

    }
}
